package com.huatai.exchange.integration.report.impl;

import com.alibaba.fastjson.JSON;
import com.faneui.common.exception.BusinessException;
import com.faneui.integration.http.HttpClientUtils;
import com.google.common.collect.Maps;
import com.huatai.exchange.integration.report.AbstractReportService;
import com.huatai.exchange.integration.report.service.ReportExportService;
import com.huatai.report.facade.enums.ExportFileTypeEnum;
import org.springframework.stereotype.Service;

import java.io.OutputStream;
import java.util.Map;

@Service
public class ReportExportServiceImpl extends AbstractReportService implements ReportExportService {


    @Override
    public void exportExcel(OutputStream os, String templateName, Map<String, Object> resvMap) throws BusinessException {
        exportExcel(os,templateName,resvMap, ExportFileTypeEnum.excel2007);
    }

    @Override
    public void exportExcel(OutputStream os, String templateName, Map<String, Object> resvMap, ExportFileTypeEnum exportFileTypeEnum) throws BusinessException {
        String url = baseUrl + "/reporttemplate/export/" + exportFileTypeEnum;
        Map<String,Object> param = Maps.newHashMap() ;
        param.put("templateName", templateName) ;
        param.put("paramJson", JSON.toJSONString(resvMap)) ;
        HttpClientUtils.downLoadFile(url,param,os);
    }
}
